home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libs / f2c / src / io.c < prev    next >
C/C++ Source or Header  |  1994-05-06  |  30KB  |  1,494 lines

  1. /****************************************************************
  2. Copyright 1990, 1991, 1993, 1994 by AT&T Bell Laboratories and Bellcore.
  3.  
  4. Permission to use, copy, modify, and distribute this software
  5. and its documentation for any purpose and without fee is hereby
  6. granted, provided that the above copyright notice appear in all
  7. copies and that both that the copyright notice and this
  8. permission notice and warranty disclaimer appear in supporting
  9. documentation, and that the names of AT&T Bell Laboratories or
  10. Bellcore or any of their entities not be used in advertising or
  11. publicity pertaining to distribution of the software without
  12. specific, written prior permission.
  13.  
  14. AT&T and Bellcore disclaim all warranties with regard to this
  15. software, including all implied warranties of merchantability
  16. and fitness.  In no event shall AT&T or Bellcore be liable for
  17. any special, indirect or consequential damages or any damages
  18. whatsoever resulting from loss of use, data or profits, whether
  19. in an action of contract, negligence or other tortious action,
  20. arising out of or in connection with the use or performance of
  21. this software.
  22. ****************************************************************/
  23.  
  24. /* Routines to generate code for I/O statements.
  25.    Some corrections and improvements due to David Wasley, U. C. Berkeley
  26. */
  27.  
  28. /* TEMPORARY */
  29. #define TYIOINT TYLONG
  30. #define SZIOINT SZLONG
  31.  
  32. #include "defs.h"
  33. #include "names.h"
  34. #include "iob.h"
  35.  
  36. extern int inqmask;
  37.  
  38. static void dofclose Argdcl((void));
  39. static void dofinquire Argdcl((void));
  40. static void dofmove Argdcl((char*));
  41. static void dofopen Argdcl((void));
  42. static void doiolist Argdcl((chainp));
  43. static void ioset Argdcl((int, int, expptr));
  44. static void ioseta Argdcl((int, Addrp));
  45. static void iosetc Argdcl((int, expptr));
  46. static void iosetip Argdcl((int, int));
  47. static void iosetlc Argdcl((int, int, int));
  48. static void putio Argdcl((expptr, expptr));
  49. static void putiocall Argdcl((expptr));
  50.  
  51. iob_data *iob_list;
  52. Addrp io_structs[9];
  53.  
  54. LOCAL char ioroutine[12];
  55.  
  56. LOCAL long ioendlab;
  57. LOCAL long ioerrlab;
  58. LOCAL int endbit;
  59. LOCAL int errbit;
  60. LOCAL long jumplab;
  61. LOCAL long skiplab;
  62. LOCAL int ioformatted;
  63. LOCAL int statstruct = NO;
  64. LOCAL struct Labelblock *skiplabel;
  65. Addrp ioblkp;
  66.  
  67. #define UNFORMATTED 0
  68. #define FORMATTED 1
  69. #define LISTDIRECTED 2
  70. #define NAMEDIRECTED 3
  71.  
  72. #define V(z)    ioc[z].iocval
  73.  
  74. #define IOALL 07777
  75.  
  76. LOCAL struct Ioclist
  77. {
  78.     char *iocname;
  79.     int iotype;
  80.     expptr iocval;
  81. }
  82. ioc[ ] =
  83. {
  84.     { "", 0 },
  85.     { "unit", IOALL },
  86.     { "fmt", M(IOREAD) | M(IOWRITE) },
  87.     { "err", IOALL },
  88.     { "end", M(IOREAD) },
  89.     { "iostat", IOALL },
  90.     { "rec", M(IOREAD) | M(IOWRITE) },
  91.     { "recl", M(IOOPEN) | M(IOINQUIRE) },
  92.     { "file", M(IOOPEN) | M(IOINQUIRE) },
  93.     { "status", M(IOOPEN) | M(IOCLOSE) },
  94.     { "access", M(IOOPEN) | M(IOINQUIRE) },
  95.     { "form", M(IOOPEN) | M(IOINQUIRE) },
  96.     { "blank", M(IOOPEN) | M(IOINQUIRE) },
  97.     { "exist", M(IOINQUIRE) },
  98.     { "opened", M(IOINQUIRE) },
  99.     { "number", M(IOINQUIRE) },
  100.     { "named", M(IOINQUIRE) },
  101.     { "name", M(IOINQUIRE) },
  102.     { "sequential", M(IOINQUIRE) },
  103.     { "direct", M(IOINQUIRE) },
  104.     { "formatted", M(IOINQUIRE) },
  105.     { "unformatted", M(IOINQUIRE) },
  106.     { "nextrec", M(IOINQUIRE) },
  107.     { "nml", M(IOREAD) | M(IOWRITE) }
  108. };
  109.  
  110. #define NIOS (sizeof(ioc)/sizeof(struct Ioclist) - 1)
  111.  
  112. /* #define IOSUNIT 1 */
  113. /* #define IOSFMT 2 */
  114. #define IOSERR 3
  115. #define IOSEND 4
  116. #define IOSIOSTAT 5
  117. #define IOSREC 6
  118. #define IOSRECL 7
  119. #define IOSFILE 8
  120. #define IOSSTATUS 9
  121. #define IOSACCESS 10
  122. #define IOSFORM 11
  123. #define IOSBLANK 12
  124. #define IOSEXISTS 13
  125. #define IOSOPENED 14
  126. #define IOSNUMBER 15
  127. #define IOSNAMED 16
  128. #define IOSNAME 17
  129. #define IOSSEQUENTIAL 18
  130. #define IOSDIRECT 19
  131. #define IOSFORMATTED 20
  132. #define IOSUNFORMATTED 21
  133. #define IOSNEXTREC 22
  134. #define IOSNML 23
  135.  
  136. #define IOSTP V(IOSIOSTAT)
  137.  
  138.  
  139. /* offsets in generated structures */
  140.  
  141. #define SZFLAG SZIOINT
  142.  
  143. /* offsets for external READ and WRITE statements */
  144.  
  145. #define XERR 0
  146. #define XUNIT    SZFLAG
  147. #define XEND    SZFLAG + SZIOINT
  148. #define XFMT    2*SZFLAG + SZIOINT
  149. #define XREC    2*SZFLAG + SZIOINT + SZADDR
  150.  
  151. /* offsets for internal READ and WRITE statements */
  152.  
  153. #define XIUNIT    SZFLAG
  154. #define XIEND    SZFLAG + SZADDR
  155. #define XIFMT    2*SZFLAG + SZADDR
  156. #define XIRLEN    2*SZFLAG + 2*SZADDR
  157. #define XIRNUM    2*SZFLAG + 2*SZADDR + SZIOINT
  158. #define XIREC    2*SZFLAG + 2*SZADDR + 2*SZIOINT
  159.  
  160. /* offsets for OPEN statements */
  161.  
  162. #define XFNAME    SZFLAG + SZIOINT
  163. #define XFNAMELEN    SZFLAG + SZIOINT + SZADDR
  164. #define XSTATUS    SZFLAG + 2*SZIOINT + SZADDR
  165. #define XACCESS    SZFLAG + 2*SZIOINT + 2*SZADDR
  166. #define XFORMATTED    SZFLAG + 2*SZIOINT + 3*SZADDR
  167. #define XRECLEN    SZFLAG + 2*SZIOINT + 4*SZADDR
  168. #define XBLANK    SZFLAG + 3*SZIOINT + 4*SZADDR
  169.  
  170. /* offset for CLOSE statement */
  171.  
  172. #define XCLSTATUS    SZFLAG + SZIOINT
  173.  
  174. /* offsets for INQUIRE statement */
  175.  
  176. #define XFILE    SZFLAG + SZIOINT
  177. #define XFILELEN    SZFLAG + SZIOINT + SZADDR
  178. #define XEXISTS    SZFLAG + 2*SZIOINT + SZADDR
  179. #define XOPEN    SZFLAG + 2*SZIOINT + 2*SZADDR
  180. #define XNUMBER    SZFLAG + 2*SZIOINT + 3*SZADDR
  181. #define XNAMED    SZFLAG + 2*SZIOINT + 4*SZADDR
  182. #define XNAME    SZFLAG + 2*SZIOINT + 5*SZADDR
  183. #define XNAMELEN    SZFLAG + 2*SZIOINT + 6*SZADDR
  184. #define XQACCESS    SZFLAG + 3*SZIOINT + 6*SZADDR
  185. #define XQACCLEN    SZFLAG + 3*SZIOINT + 7*SZADDR
  186. #define XSEQ    SZFLAG + 4*SZIOINT + 7*SZADDR
  187. #define XSEQLEN    SZFLAG + 4*SZIOINT + 8*SZADDR
  188. #define XDIRECT    SZFLAG + 5*SZIOINT + 8*SZADDR
  189. #define XDIRLEN    SZFLAG + 5*SZIOINT + 9*SZADDR
  190. #define XFORM    SZFLAG + 6*SZIOINT + 9*SZADDR
  191. #define XFORMLEN    SZFLAG + 6*SZIOINT + 10*SZADDR
  192. #define XFMTED    SZFLAG + 7*SZIOINT + 10*SZADDR
  193. #define XFMTEDLEN    SZFLAG + 7*SZIOINT + 11*SZADDR
  194. #define XUNFMT    SZFLAG + 8*SZIOINT + 11*SZADDR
  195. #define XUNFMTLEN    SZFLAG + 8*SZIOINT + 12*SZADDR
  196. #define XQRECL    SZFLAG + 9*SZIOINT + 12*SZADDR
  197. #define XNEXTREC    SZFLAG + 9*SZIOINT + 13*SZADDR
  198. #define XQBLANK    SZFLAG + 9*SZIOINT + 14*SZADDR
  199. #define XQBLANKLEN    SZFLAG + 9*SZIOINT + 15*SZADDR
  200.  
  201. LOCAL char *cilist_names[] = {
  202.     "cilist",
  203.     "cierr",
  204.     "ciunit",
  205.     "ciend",
  206.     "cifmt",
  207.     "cirec"
  208.     };
  209. LOCAL char *icilist_names[] = {
  210.     "icilist",
  211.     "icierr",
  212.     "iciunit",
  213.     "iciend",
  214.     "icifmt",
  215.     "icirlen",
  216.     "icirnum"
  217.     };
  218. LOCAL char *olist_names[] = {
  219.     "olist",
  220.     "oerr",
  221.     "ounit",
  222.     "ofnm",
  223.     "ofnmlen",
  224.     "osta",
  225.     "oacc",
  226.     "ofm",
  227.     "orl",
  228.     "oblnk"
  229.     };
  230. LOCAL char *cllist_names[] = {
  231.     "cllist",
  232.     "cerr",
  233.     "cunit",
  234.     "csta"
  235.     };
  236. LOCAL char *alist_names[] = {
  237.     "alist",
  238.     "aerr",
  239.     "aunit"
  240.     };
  241. LOCAL char *inlist_names[] = {
  242.     "inlist",
  243.     "inerr",
  244.     "inunit",
  245.     "infile",
  246.     "infilen",
  247.     "inex",
  248.     "inopen",
  249.     "innum",
  250.     "innamed",
  251.     "inname",
  252.     "innamlen",
  253.     "inacc",
  254.     "inacclen",
  255.     "inseq",
  256.     "inseqlen",
  257.     "indir",
  258.     "indirlen",
  259.     "infmt",
  260.     "infmtlen",
  261.     "inform",
  262.     "informlen",
  263.     "inunf",
  264.     "inunflen",
  265.     "inrecl",
  266.     "innrec",
  267.     "inblank",
  268.     "inblanklen"
  269.     };
  270.  
  271. LOCAL char **io_fields;
  272.  
  273. #define zork(n,t) n, sizeof(n)/sizeof(char *) - 1, t
  274.  
  275. LOCAL io_setup io_stuff[] = {
  276.     zork(cilist_names, TYCILIST),    /* external read/write */
  277.     zork(inlist_names, TYINLIST),    /* inquire */
  278.     zork(olist_names,  TYOLIST),    /* open */
  279.     zork(cllist_names, TYCLLIST),    /* close */
  280.     zork(alist_names,  TYALIST),    /* rewind */
  281.     zork(alist_names,  TYALIST),    /* backspace */
  282.     zork(alist_names,  TYALIST),    /* endfile */
  283.     zork(icilist_names,TYICILIST),    /* internal read */
  284.     zork(icilist_names,TYICILIST)    /* internal write */
  285.     };
  286.  
  287. #undef zork
  288.  
  289.  int
  290. #ifdef KR_headers
  291. fmtstmt(lp)
  292.     register struct Labelblock *lp;
  293. #else
  294. fmtstmt(register struct Labelblock *lp)
  295. #endif
  296. {
  297.     if(lp == NULL)
  298.     {
  299.         execerr("unlabeled format statement" , CNULL);
  300.         return(-1);
  301.     }
  302.     if(lp->labtype == LABUNKNOWN)
  303.     {
  304.         lp->labtype = LABFORMAT;
  305.         lp->labelno = newlabel();
  306.     }
  307.     else if(lp->labtype != LABFORMAT)
  308.     {
  309.         execerr("bad format number", CNULL);
  310.         return(-1);
  311.     }
  312.     return(lp->labelno);
  313. }
  314.  
  315.  
  316.  void
  317. #ifdef KR_headers
  318. setfmt(lp)
  319.     struct Labelblock *lp;
  320. #else
  321. setfmt(struct Labelblock *lp)
  322. #endif
  323. {
  324.     int n;
  325.     char *s0;
  326.     register char *s, *se, *t;
  327.     register k;
  328.  
  329.     s0 = s = lexline(&n);
  330.     se = t = s + n;
  331.  
  332.     /* warn of trivial errors, e.g. "  11 CONTINUE" (one too few spaces) */
  333.     /* following FORMAT... */
  334.  
  335.     if (n <= 0)
  336.         warn("No (...) after FORMAT");
  337.     else if (*s != '(')
  338.         warni("%c rather than ( after FORMAT", *s);
  339.     else if (se[-1] != ')') {
  340.         *se = 0;
  341.         while(--t > s && *t != ')') ;
  342.         if (t <= s)
  343.             warn("No ) at end of FORMAT statement");
  344.         else if (se - t > 30)
  345.             warn1("Extraneous text at end of FORMAT: ...%s", se-12);
  346.         else
  347.             warn1("Extraneous text at end of FORMAT: %s", t+1);
  348.         t = se;
  349.         }
  350.  
  351.     /* fix MYQUOTES (\002's) and \\'s */
  352.  
  353.     while(s < se)
  354.         switch(*s++) {
  355.             case 2:
  356.                 t += 3; break;
  357.             case '"':
  358.             case '\\':
  359.                 t++; break;
  360.             }
  361.     s = s0;
  362.     if (lp) {
  363.         lp->fmtstring = t = mem((int)(t - s + 1), 0);
  364.         while(s < se)
  365.             switch(k = *s++) {
  366.                 case 2:
  367.                     t[0] = '\\';
  368.                     t[1] = '0';
  369.                     t[2] = '0';
  370.                     t[3] = '2';
  371.                     t += 4;
  372.                     break;
  373.                 case '"':
  374.                 case '\\':
  375.                     *t++ = '\\';
  376.                     /* no break */
  377.                 default:
  378.                     *t++ = k;
  379.                 }
  380.         *t = 0;
  381.         }
  382.     flline();
  383. }
  384.  
  385.  
  386.  void
  387. #ifdef KR_headers
  388. startioctl()
  389. #else
  390. startioctl()
  391. #endif
  392. {
  393.     register int i;
  394.  
  395.     inioctl = YES;
  396.     nioctl = 0;
  397.     ioformatted = UNFORMATTED;
  398.     for(i = 1 ; i<=NIOS ; ++i)
  399.         V(i) = NULL;
  400. }
  401.  
  402.  static long
  403. newiolabel(Void) {
  404.     long rv;
  405.     rv = ++lastiolabno;
  406.     skiplabel = mklabel(rv);
  407.     skiplabel->labdefined = 1;
  408.     return rv;
  409.     }
  410.  
  411.  void
  412. endioctl(Void)
  413. {
  414.     int i;
  415.     expptr p;
  416.     struct io_setup *ios;
  417.  
  418.     inioctl = NO;
  419.  
  420.     /* set up for error recovery */
  421.  
  422.     ioerrlab = ioendlab = skiplab = jumplab = 0;
  423.  
  424.     if(p = V(IOSEND))
  425.         if(ISICON(p))
  426.             execlab(ioendlab = p->constblock.Const.ci);
  427.         else
  428.             err("bad end= clause");
  429.  
  430.     if(p = V(IOSERR))
  431.         if(ISICON(p))
  432.             execlab(ioerrlab = p->constblock.Const.ci);
  433.         else
  434.             err("bad err= clause");
  435.  
  436.     if(IOSTP)
  437.         if(IOSTP->tag!=TADDR || ! ISINT(IOSTP->addrblock.vtype) )
  438.         {
  439.             err("iostat must be an integer variable");
  440.             frexpr(IOSTP);
  441.             IOSTP = NULL;
  442.         }
  443.  
  444.     if(iostmt == IOREAD)
  445.     {
  446.         if(IOSTP)
  447.         {
  448.             if(ioerrlab && ioendlab && ioerrlab==ioendlab)
  449.                 jumplab = ioerrlab;
  450.             else
  451.                 skiplab = jumplab = newiolabel();
  452.         }
  453.         else    {
  454.             if(ioerrlab && ioendlab && ioerrlab!=ioendlab)
  455.             {
  456.                 IOSTP = (expptr) mktmp(TYINT, ENULL);
  457.                 skiplab = jumplab = newiolabel();
  458.             }
  459.             else
  460.                 jumplab = (ioerrlab ? ioerrlab : ioendlab);
  461.         }
  462.     }
  463.     else if(iostmt == IOWRITE)
  464.     {
  465.         if(IOSTP && !ioerrlab)
  466.             skiplab = jumplab = newiolabel();
  467.         else
  468.             jumplab = ioerrlab;
  469.     }
  470.     else
  471.         jumplab = ioerrlab;
  472.  
  473.     endbit = IOSTP!=NULL || ioendlab!=0;    /* for use in startrw() */
  474.     errbit = IOSTP!=NULL || ioerrlab!=0;
  475.     if (jumplab && !IOSTP)
  476.         IOSTP = (expptr) mktmp(TYINT, ENULL);
  477.  
  478.     if(iostmt!=IOREAD && iostmt!=IOWRITE)
  479.     {
  480.         ios = io_stuff + iostmt;
  481.         io_fields = ios->fields;
  482.         ioblkp = io_structs[iostmt];
  483.         if(ioblkp == NULL)
  484.             io_structs[iostmt] = ioblkp =
  485.                 autovar(1, ios->type, ENULL, "");
  486.         ioset(TYIOINT, XERR, ICON(errbit));
  487.     }
  488.  
  489.     switch(iostmt)
  490.     {
  491.     case IOOPEN:
  492.         dofopen();
  493.         break;
  494.  
  495.     case IOCLOSE:
  496.         dofclose();
  497.         break;
  498.  
  499.     case IOINQUIRE:
  500.         dofinquire();
  501.         break;
  502.  
  503.     case IOBACKSPACE:
  504.         dofmove("f_back");
  505.         break;
  506.  
  507.     case IOREWIND:
  508.         dofmove("f_rew");
  509.         break;
  510.  
  511.     case IOENDFILE:
  512.         dofmove("f_end");
  513.         break;
  514.  
  515.     case IOREAD:
  516.     case IOWRITE:
  517.         startrw();
  518.         break;
  519.  
  520.     default:
  521.         fatali("impossible iostmt %d", iostmt);
  522.     }
  523.     for(i = 1 ; i<=NIOS ; ++i)
  524.         if(i!=IOSIOSTAT && V(i)!=NULL)
  525.             frexpr(V(i));
  526. }
  527.  
  528.  
  529.  int
  530. iocname(Void)
  531. {
  532.     register int i;
  533.     int found, mask;
  534.  
  535.     found = 0;
  536.     mask = M(iostmt);
  537.     for(i = 1 ; i <= NIOS ; ++i)
  538.         if(!strcmp(ioc[i].iocname, token))
  539.             if(ioc[i].iotype & mask)
  540.                 return(i);
  541.             else {
  542.                 found = i;
  543.                 break;
  544.                 }
  545.     if(found) {
  546.         if (iostmt == IOOPEN && !strcmp(ioc[i].iocname, "name")) {
  547.             NOEXT("open with \"name=\" treated as \"file=\"");
  548.             for(i = 1; strcmp(ioc[i].iocname, "file"); i++);
  549.             return i;
  550.             }
  551.         errstr("invalid control %s for statement", ioc[found].iocname);
  552.         }
  553.     else
  554.         errstr("unknown iocontrol %s", token);
  555.     return(IOSBAD);
  556. }
  557.  
  558.  
  559.  void
  560. #ifdef KR_headers
  561. ioclause(n, p)
  562.     register int n;
  563.     register expptr p;
  564. #else
  565. ioclause(register int n, register expptr p)
  566. #endif
  567. {
  568.     struct Ioclist *iocp;
  569.  
  570.     ++nioctl;
  571.     if(n == IOSBAD)
  572.         return;
  573.     if(n == IOSPOSITIONAL)
  574.         {
  575.         n = nioctl;
  576.         if (n == IOSFMT) {
  577.             if (iostmt == IOOPEN) {
  578.                 n = IOSFILE;
  579.                 NOEXT("file= specifier omitted from open");
  580.                 }
  581.             else if (iostmt < IOREAD)
  582.                 goto illegal;
  583.             }
  584.         else if(n > IOSFMT)
  585.             {
  586.  illegal:
  587.             err("illegal positional iocontrol");
  588.             return;
  589.             }
  590.         }
  591.     else if (n == IOSNML)
  592.         n = IOSFMT;
  593.  
  594.     if(p == NULL)
  595.     {
  596.         if(n == IOSUNIT)
  597.             p = (expptr) (iostmt==IOREAD ? IOSTDIN : IOSTDOUT);
  598.         else if(n != IOSFMT)
  599.         {
  600.             err("illegal * iocontrol");
  601.             return;
  602.         }
  603.     }
  604.     if(n == IOSFMT)
  605.         ioformatted = (p==NULL ? LISTDIRECTED : FORMATTED);
  606.  
  607.     iocp = & ioc[n];
  608.     if(iocp->iocval == NULL)
  609.     {
  610.         if(n!=IOSFMT && ( n!=IOSUNIT || (p && p->headblock.vtype!=TYCHAR) ) )
  611.             p = fixtype(p);
  612.         else if (p && p->tag == TPRIM
  613.                && p->primblock.namep->vclass == CLUNKNOWN) {
  614.             /* kludge made necessary by attempt to infer types
  615.              * for untyped external parameters: given an error
  616.              * in calling sequences, an integer argument might
  617.              * tentatively be assumed TYCHAR; this would otherwise
  618.              * be corrected too late in startrw after startrw
  619.              * had decided this to be an internal file.
  620.              */
  621.             vardcl(p->primblock.namep);
  622.             p->primblock.vtype = p->primblock.namep->vtype;
  623.             }
  624.         iocp->iocval = p;
  625.     }
  626.     else
  627.         errstr("iocontrol %s repeated", iocp->iocname);
  628. }
  629.  
  630. /* io list item */
  631.  
  632.  void
  633. #ifdef KR_headers
  634. doio(list)
  635.     chainp list;
  636. #else
  637. doio(chainp list)
  638. #endif
  639. {
  640.     if(ioformatted == NAMEDIRECTED)
  641.     {
  642.         if(list)
  643.             err("no I/O list allowed in NAMELIST read/write");
  644.     }
  645.     else
  646.     {
  647.         doiolist(list);
  648.         ioroutine[0] = 'e';
  649.         if (skiplab || ioroutine[4] == 'l')
  650.             jumplab = 0;
  651.         putiocall( call0(TYINT, ioroutine) );
  652.     }
  653. }
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  LOCAL void
  660. #ifdef KR_headers
  661. doiolist(p0)
  662.     chainp p0;
  663. #else
  664. doiolist(chainp p0)
  665. #endif
  666. {
  667.     chainp p;
  668.     register tagptr q;
  669.     register expptr qe;
  670.     register Namep qn;
  671.     Addrp tp;
  672.     int range;
  673.     extern char *ohalign;
  674.  
  675.     for (p = p0 ; p ; p = p->nextp)
  676.     {
  677.         q = (tagptr)p->datap;
  678.         if(q->tag == TIMPLDO)
  679.         {
  680.             exdo(range=newlabel(), (Namep)0,
  681.                 q->impldoblock.impdospec);
  682.             doiolist(q->impldoblock.datalist);
  683.             enddo(range);
  684.             free( (charptr) q);
  685.         }
  686.         else    {
  687.             if(q->tag==TPRIM && q->primblock.argsp==NULL
  688.                 && q->primblock.namep->vdim!=NULL)
  689.             {
  690.                 vardcl(qn = q->primblock.namep);
  691.                 if(qn->vdim->nelt) {
  692.                     putio( fixtype(cpexpr(qn->vdim->nelt)),
  693.                         (expptr)mkscalar(qn) );
  694.                     qn->vlastdim = 0;
  695.                     }
  696.                 else
  697.                     err("attempt to i/o array of unknown size");
  698.             }
  699.             else if(q->tag==TPRIM && q->primblock.argsp==NULL &&
  700.                 (qe = (expptr) memversion(q->primblock.namep)) )
  701.                 putio(ICON(1),qe);
  702.             else if (ISCONST(q) && q->constblock.vtype == TYCHAR) {
  703.                 halign = 0;
  704.                 putio(ICON(1), qe = fixtype(cpexpr(q)));
  705.                 halign = ohalign;
  706.                 }
  707.             else if(((qe = fixtype(cpexpr(q)))->tag==TADDR &&
  708.                 (qe->addrblock.uname_tag != UNAM_CONST ||
  709.                 !ISCOMPLEX(qe -> addrblock.vtype))) ||
  710.                 (qe -> tag == TCONST && !ISCOMPLEX(qe ->
  711.                 headblock.vtype))) {
  712.                 if (qe -> tag == TCONST)
  713.                     qe = (expptr) putconst((Constp)qe);
  714.                 putio(ICON(1), qe);
  715.             }
  716.             else if(qe->headblock.vtype != TYERROR)
  717.             {
  718.                 if(iostmt == IOWRITE)
  719.                 {
  720.                     expptr qvl;
  721.                     qvl = NULL;
  722.                     if( ISCHAR(qe) )
  723.                     {
  724.                         qvl = (expptr)
  725.                             cpexpr(qe->headblock.vleng);
  726.                         tp = mktmp(qe->headblock.vtype,
  727.                             ICON(lencat(qe)));
  728.                     }
  729.                     else
  730.                         tp = mktmp(qe->headblock.vtype,
  731.                             qe->headblock.vleng);
  732.                     puteq( cpexpr((expptr)tp), qe);
  733.                     if(qvl)    /* put right length on block */
  734.                     {
  735.                         frexpr(tp->vleng);
  736.                         tp->vleng = qvl;
  737.                     }
  738.                     putio(ICON(1), (expptr)tp);
  739.                 }
  740.                 else
  741.                     err("non-left side in READ list");
  742.             }
  743.             frexpr(q);
  744.         }
  745.     }
  746.     frchain( &p0 );
  747. }
  748.  
  749.  int iocalladdr = TYADDR;    /* for fixing TYADDR in saveargtypes */
  750.  int typeconv[TYERROR+1] = {
  751. #ifdef TYQUAD
  752.         0, 1, 11, 2, 3, 14, 4, 5, 6, 7, 12, 13, 8, 9, 10, 15
  753. #else
  754.         0, 1, 11, 2, 3,     4, 5, 6, 7, 12, 13, 8, 9, 10, 14
  755. #endif
  756.         };
  757.  
  758.  LOCAL void
  759. #ifdef KR_headers
  760. putio(nelt, addr)
  761.     expptr nelt;
  762.     register expptr addr;
  763. #else
  764. putio(expptr nelt, register expptr addr)
  765. #endif
  766. {
  767.     int type;
  768.     register expptr q;
  769.     register Addrp c = 0;
  770.  
  771.     type = addr->headblock.vtype;
  772.     if(ioformatted!=LISTDIRECTED && ISCOMPLEX(type) )
  773.     {
  774.         nelt = mkexpr(OPSTAR, ICON(2), nelt);
  775.         type -= (TYCOMPLEX-TYREAL);
  776.     }
  777.  
  778.     /* pass a length with every item.  for noncharacter data, fake one */
  779.     if(type != TYCHAR)
  780.     {
  781.  
  782.         if( ISCONST(addr) )
  783.             addr = (expptr) putconst((Constp)addr);
  784.         c = ALLOC(Addrblock);
  785.         c->tag = TADDR;
  786.         c->vtype = TYLENG;
  787.         c->vstg = STGAUTO;
  788.         c->ntempelt = 1;
  789.         c->isarray = 1;
  790.         c->memoffset = ICON(0);
  791.         c->uname_tag = UNAM_IDENT;
  792.         c->charleng = 1;
  793.         sprintf(c->user.ident, "(ftnlen)sizeof(%s)", typename[type]);
  794.         addr = mkexpr(OPCHARCAST, addr, ENULL);
  795.         }
  796.  
  797.     nelt = fixtype( mkconv(tyioint,nelt) );
  798.     if(ioformatted == LISTDIRECTED) {
  799.         expptr mc = mkconv(tyioint, ICON(typeconv[type]));
  800.         q = c    ? call4(TYINT, "do_lio", mc, nelt, addr, (expptr)c)
  801.             : call3(TYINT, "do_lio", mc, nelt, addr);
  802.         }
  803.     else {
  804.         char *s = ioformatted==FORMATTED ? "do_fio" : "do_uio";
  805.         q = c    ? call3(TYINT, s, nelt, addr, (expptr)c)
  806.             : call2(TYINT, s, nelt, addr);
  807.         }
  808.     iocalladdr = TYCHAR;
  809.     putiocall(q);
  810.     iocalladdr = TYADDR;
  811. }
  812.  
  813.  
  814.  
  815.  void
  816. endio(Void)
  817. {
  818.     if(skiplab)
  819.     {
  820.         if (ioformatted != NAMEDIRECTED)
  821.             p1_label((long)(skiplabel - labeltab));
  822.         if(ioendlab) {
  823.             exif( mkexpr(OPLT, cpexpr(IOSTP), ICON(0)));
  824.             exgoto(execlab(ioendlab));
  825.             exendif();
  826.             }
  827.         if(ioerrlab) {
  828.             exif( mkexpr(iostmt==IOREAD||iostmt==IOWRITE
  829.                     ? OPGT : OPNE,
  830.                 cpexpr(IOSTP), ICON(0)));
  831.             exgoto(execlab(ioerrlab));
  832.             exendif();
  833.             }
  834.     }
  835.  
  836.     if(IOSTP)
  837.         frexpr(IOSTP);
  838. }
  839.  
  840.  
  841.  
  842.  LOCAL void
  843. #ifdef KR_headers
  844. putiocall(q)
  845.     register expptr q;
  846. #else
  847. putiocall(register expptr q)
  848. #endif
  849. {
  850.     int tyintsave;
  851.  
  852.     tyintsave = tyint;
  853.     tyint = tyioint;    /* for -I2 and -i2 */
  854.  
  855.     if(IOSTP)
  856.     {
  857.         q->headblock.vtype = TYINT;
  858.         q = fixexpr((Exprp)mkexpr(OPASSIGN, cpexpr(IOSTP), q));
  859.     }
  860.     putexpr(q);
  861.     if(jumplab) {
  862.         exif(mkexpr(OPNE, cpexpr(IOSTP), ICON(0)));
  863.         exgoto(execlab(jumplab));
  864.         exendif();
  865.         }
  866.     tyint = tyintsave;
  867. }
  868.  
  869.  void
  870. #ifdef KR_headers
  871. fmtname(np, q)
  872.     Namep np;
  873.     register Addrp q;
  874. #else
  875. fmtname(Namep np, register Addrp q)
  876. #endif
  877. {
  878.     register int k;
  879.     register char *s, *t;
  880.     extern chainp assigned_fmts;
  881.  
  882.     if (!np->vfmt_asg) {
  883.         np->vfmt_asg = 1;
  884.         assigned_fmts = mkchain((char *)np, assigned_fmts);
  885.         }
  886.     k = strlen(s = np->fvarname);
  887.     if (k < IDENT_LEN - 4) {
  888.         q->uname_tag = UNAM_IDENT;
  889.         t = q->user.ident;
  890.         }
  891.     else {
  892.         q->uname_tag = UNAM_CHARP;
  893.         q->user.Charp = t = mem(k + 5,0);
  894.         }
  895.     sprintf(t, "%s_fmt", s);
  896.     }
  897.  
  898.  LOCAL Addrp
  899. #ifdef KR_headers
  900. asg_addr(p)
  901.     union Expression *p;
  902. #else
  903. asg_addr(union Expression *p)
  904. #endif
  905. {
  906.     register Addrp q;
  907.  
  908.     if (p->tag != TPRIM)
  909.         badtag("asg_addr", p->tag);
  910.     q = ALLOC(Addrblock);
  911.     q->tag = TADDR;
  912.     q->vtype = TYCHAR;
  913.     q->vstg = STGAUTO;
  914.     q->ntempelt = 1;
  915.     q->isarray = 0;
  916.     q->memoffset = ICON(0);
  917.     fmtname(p->primblock.namep, q);
  918.     return q;
  919.     }
  920.  
  921.  void
  922. startrw(Void)
  923. {
  924.     register expptr p;
  925.     register Namep np;
  926.     register Addrp unitp, fmtp, recp;
  927.     register expptr nump;
  928.     int iostmt1;
  929.     flag intfile, sequential, ok, varfmt;
  930.     struct io_setup *ios;
  931.  
  932.     /* First look at all the parameters and determine what is to be done */
  933.  
  934.     ok = YES;
  935.     statstruct = YES;
  936.  
  937.     intfile = NO;
  938.     if(p = V(IOSUNIT))
  939.     {
  940.         if( ISINT(p->headblock.vtype) ) {
  941.  int_unit:
  942.             unitp = (Addrp) cpexpr(p);
  943.             }
  944.         else if(p->headblock.vtype == TYCHAR)
  945.         {
  946.             if (nioctl == 1 && iostmt == IOREAD) {
  947.                 /* kludge to recognize READ(format expr) */
  948.                 V(IOSFMT) = p;
  949.                 V(IOSUNIT) = p = (expptr) IOSTDIN;
  950.                 ioformatted = FORMATTED;
  951.                 goto int_unit;
  952.                 }
  953.             intfile = YES;
  954.             if(p->tag==TPRIM && p->primblock.argsp==NULL &&
  955.                 (np = p->primblock.namep)->vdim!=NULL)
  956.             {
  957.                 vardcl(np);
  958.                 if(nump = np->vdim->nelt)
  959.                 {
  960.                     nump = fixtype(cpexpr(nump));
  961.                     if( ! ISCONST(nump) ) {
  962.                         statstruct = NO;
  963.                         np->vlastdim = 0;
  964.                         }
  965.                 }
  966.                 else
  967.                 {
  968.                     err("attempt to use internal unit array of unknown size");
  969.                     ok = NO;
  970.                     nump = ICON(1);
  971.                 }
  972.                 unitp = mkscalar(np);
  973.             }
  974.             else    {
  975.                 nump = ICON(1);
  976.                 unitp = (Addrp /*pjw */) fixtype(cpexpr(p));
  977.             }
  978.             if(! isstatic((expptr)unitp) )
  979.                 statstruct = NO;
  980.         }
  981.         else {
  982.             err("unit specifier not of type integer or character");
  983.             ok = NO;
  984.             }
  985.     }
  986.     else
  987.     {
  988.         err("bad unit specifier");
  989.         ok = NO;
  990.     }
  991.  
  992.     sequential = YES;
  993.     if(p = V(IOSREC))
  994.         if( ISINT(p->headblock.vtype) )
  995.         {
  996.             recp = (Addrp) cpexpr(p);
  997.             sequential = NO;
  998.         }
  999.         else    {
  1000.             err("bad REC= clause");
  1001.             ok = NO;
  1002.         }
  1003.     else
  1004.         recp = NULL;
  1005.  
  1006.  
  1007.     varfmt = YES;
  1008.     fmtp = NULL;
  1009.     if(p = V(IOSFMT))
  1010.     {
  1011.         if(p->tag==TPRIM && p->primblock.argsp==NULL)
  1012.         {
  1013.             np = p->primblock.namep;
  1014.             if(np->vclass == CLNAMELIST)
  1015.             {
  1016.                 ioformatted = NAMEDIRECTED;
  1017.                 fmtp = (Addrp) fixtype(p);
  1018.                 V(IOSFMT) = (expptr)fmtp;
  1019.                 if (skiplab)
  1020.                     jumplab = 0;
  1021.                 goto endfmt;
  1022.             }
  1023.             vardcl(np);
  1024.             if(np->vdim)
  1025.             {
  1026.                 if( ! ONEOF(np->vstg, MSKSTATIC) )
  1027.                     statstruct = NO;
  1028.                 fmtp = mkscalar(np);
  1029.                 goto endfmt;
  1030.             }
  1031.             if( ISINT(np->vtype) )    /* ASSIGNed label */
  1032.             {
  1033.                 statstruct = NO;
  1034.                 varfmt = YES;
  1035.                 fmtp = asg_addr(p);
  1036.                 goto endfmt;
  1037.             }
  1038.         }
  1039.         p = V(IOSFMT) = fixtype(p);
  1040.         if(p->headblock.vtype == TYCHAR
  1041.             /* Since we allow write(6,n)        */
  1042.             /* we may as well allow write(6,n(2))    */
  1043.         || p->tag == TADDR && ISINT(p->addrblock.vtype))
  1044.         {
  1045.             if( ! isstatic(p) )
  1046.                 statstruct = NO;
  1047.             fmtp = (Addrp) cpexpr(p);
  1048.         }
  1049.         else if( ISICON(p) )
  1050.         {
  1051.             struct Labelblock *lp;
  1052.             lp = mklabel(p->constblock.Const.ci);
  1053.             if (fmtstmt(lp) > 0)
  1054.             {
  1055.                 fmtp = (Addrp)mkaddcon(lp->stateno);
  1056.                 /* lp->stateno for names fmt_nnn */
  1057.                 lp->fmtlabused = 1;
  1058.                 varfmt = NO;
  1059.             }
  1060.             else
  1061.                 ioformatted = UNFORMATTED;
  1062.         }
  1063.         else    {
  1064.             err("bad format descriptor");
  1065.             ioformatted = UNFORMATTED;
  1066.             ok = NO;
  1067.         }
  1068.     }
  1069.     else
  1070.         fmtp = NULL;
  1071.  
  1072. endfmt:
  1073.     if(intfile) {
  1074.         if (ioformatted==UNFORMATTED) {
  1075.             err("unformatted internal I/O not allowed");
  1076.             ok = NO;
  1077.             }
  1078.         if (recp) {
  1079.             err("direct internal I/O not allowed");
  1080.             ok = NO;
  1081.             }
  1082.         }
  1083.     if(!sequential && ioformatted==LISTDIRECTED)
  1084.     {
  1085.         err("direct list-directed I/O not allowed");
  1086.         ok = NO;
  1087.     }
  1088.     if(!sequential && ioformatted==NAMEDIRECTED)
  1089.     {
  1090.         err("direct namelist I/O not allowed");
  1091.         ok = NO;
  1092.     }
  1093.  
  1094.     if( ! ok ) {
  1095.         statstruct = NO;
  1096.         return;
  1097.         }
  1098.  
  1099.     /*
  1100.    Now put out the I/O structure, statically if all the clauses
  1101.    are constants, dynamically otherwise
  1102. */
  1103.  
  1104.     if (intfile) {
  1105.         ios = io_stuff + iostmt;
  1106.         iostmt1 = IOREAD;
  1107.         }
  1108.     else {
  1109.         ios = io_stuff;
  1110.         iostmt1 = 0;
  1111.         }
  1112.     io_fields = ios->fields;
  1113.     if(statstruct)
  1114.     {
  1115.         ioblkp = ALLOC(Addrblock);
  1116.         ioblkp->tag = TADDR;
  1117.         ioblkp->vtype = ios->type;
  1118.         ioblkp->vclass = CLVAR;
  1119.         ioblkp->vstg = STGINIT;
  1120.         ioblkp->memno = ++lastvarno;
  1121.         ioblkp->memoffset = ICON(0);
  1122.         ioblkp -> uname_tag = UNAM_IDENT;
  1123.         new_iob_data(ios,
  1124.             temp_name("io_", lastvarno, ioblkp->user.ident));            }
  1125.     else if(!(ioblkp = io_structs[iostmt1]))
  1126.         io_structs[iostmt1] = ioblkp =
  1127.             autovar(1, ios->type, ENULL, "");
  1128.  
  1129.     ioset(TYIOINT, XERR, ICON(errbit));
  1130.     if(iostmt == IOREAD)
  1131.         ioset(TYIOINT, (intfile ? XIEND : XEND), ICON(endbit) );
  1132.  
  1133.     if(intfile)
  1134.     {
  1135.         ioset(TYIOINT, XIRNUM, nump);
  1136.         ioset(TYIOINT, XIRLEN, cpexpr(unitp->vleng) );
  1137.         ioseta(XIUNIT, unitp);
  1138.     }
  1139.     else
  1140.         ioset(TYIOINT, XUNIT, (expptr) unitp);
  1141.  
  1142.     if(recp)
  1143.         ioset(TYIOINT, /* intfile ? XIREC : */ XREC, (expptr) recp);
  1144.  
  1145.     if(varfmt)
  1146.         ioseta( intfile ? XIFMT : XFMT , fmtp);
  1147.     else
  1148.         ioset(TYADDR, intfile ? XIFMT : XFMT, (expptr) fmtp);
  1149.  
  1150.     ioroutine[0] = 's';
  1151.     ioroutine[1] = '_';
  1152.     ioroutine[2] = iostmt==IOREAD ? 'r' : 'w';
  1153.     ioroutine[3] = "ds"[sequential];
  1154.     ioroutine[4] = "ufln"[ioformatted];
  1155.     ioroutine[5] = "ei"[intfile];
  1156.     ioroutine[6] = '\0';
  1157.  
  1158.     putiocall( call1(TYINT, ioroutine, cpexpr((expptr)ioblkp) ));
  1159.  
  1160.     if(statstruct)
  1161.     {
  1162.         frexpr((expptr)ioblkp);
  1163.         statstruct = NO;
  1164.         ioblkp = 0;    /* unnecessary */
  1165.     }
  1166. }
  1167.  
  1168.  
  1169.  
  1170.  LOCAL void
  1171. dofopen(Void)
  1172. {
  1173.     register expptr p;
  1174.  
  1175.     if( (p = V(IOSUNIT)) && ISINT(p->headblock.vtype) )
  1176.         ioset(TYIOINT, XUNIT, cpexpr(p) );
  1177.     else
  1178.         err("bad unit in open");
  1179.     if( (p = V(IOSFILE)) )
  1180.         if(p->headblock.vtype == TYCHAR)
  1181.             ioset(TYIOINT, XFNAMELEN, cpexpr(p->headblock.vleng) );
  1182.         else
  1183.             err("bad file in open");
  1184.  
  1185.     iosetc(XFNAME, p);
  1186.  
  1187.     if(p = V(IOSRECL))
  1188.         if( ISINT(p->headblock.vtype) )
  1189.             ioset(TYIOINT, XRECLEN, cpexpr(p) );
  1190.         else
  1191.             err("bad recl");
  1192.     else
  1193.         ioset(TYIOINT, XRECLEN, ICON(0) );
  1194.  
  1195.     iosetc(XSTATUS, V(IOSSTATUS));
  1196.     iosetc(XACCESS, V(IOSACCESS));
  1197.     iosetc(XFORMATTED, V(IOSFORM));
  1198.     iosetc(XBLANK, V(IOSBLANK));
  1199.  
  1200.     putiocall( call1(TYINT, "f_open", cpexpr((expptr)ioblkp) ));
  1201. }
  1202.  
  1203.  
  1204.  LOCAL void
  1205. dofclose(Void)
  1206. {
  1207.     register expptr p;
  1208.  
  1209.     if( (p = V(IOSUNIT)) && ISINT(p->headblock.vtype) )
  1210.     {
  1211.         ioset(TYIOINT, XUNIT, cpexpr(p) );
  1212.         iosetc(XCLSTATUS, V(IOSSTATUS));
  1213.         putiocall( call1(TYINT, "f_clos", cpexpr((expptr)ioblkp)) );
  1214.     }
  1215.     else
  1216.         err("bad unit in close statement");
  1217. }
  1218.  
  1219.  
  1220.  LOCAL void
  1221. dofinquire(Void)
  1222. {
  1223.     register expptr p;
  1224.     if(p = V(IOSUNIT))
  1225.     {
  1226.         if( V(IOSFILE) )
  1227.             err("inquire by unit or by file, not both");
  1228.         ioset(TYIOINT, XUNIT, cpexpr(p) );
  1229.     }
  1230.     else if( ! V(IOSFILE) )
  1231.         err("must inquire by unit or by file");
  1232.     iosetlc(IOSFILE, XFILE, XFILELEN);
  1233.     iosetip(IOSEXISTS, XEXISTS);
  1234.     iosetip(IOSOPENED, XOPEN);
  1235.     iosetip(IOSNUMBER, XNUMBER);
  1236.     iosetip(IOSNAMED, XNAMED);
  1237.     iosetlc(IOSNAME, XNAME, XNAMELEN);
  1238.     iosetlc(IOSACCESS, XQACCESS, XQACCLEN);
  1239.     iosetlc(IOSSEQUENTIAL, XSEQ, XSEQLEN);
  1240.     iosetlc(IOSDIRECT, XDIRECT, XDIRLEN);
  1241.     iosetlc(IOSFORM, XFORM, XFORMLEN);
  1242.     iosetlc(IOSFORMATTED, XFMTED, XFMTEDLEN);
  1243.     iosetlc(IOSUNFORMATTED, XUNFMT, XUNFMTLEN);
  1244.     iosetip(IOSRECL, XQRECL);
  1245.     iosetip(IOSNEXTREC, XNEXTREC);
  1246.     iosetlc(IOSBLANK, XQBLANK, XQBLANKLEN);
  1247.  
  1248.     putiocall( call1(TYINT,  "f_inqu", cpexpr((expptr)ioblkp) ));
  1249. }
  1250.  
  1251.  
  1252.  
  1253.  LOCAL void
  1254. #ifdef KR_headers
  1255. dofmove(subname)
  1256.     char *subname;
  1257. #else
  1258. dofmove(char *subname)
  1259. #endif
  1260. {
  1261.     register expptr p;
  1262.  
  1263.     if( (p = V(IOSUNIT)) && ISINT(p->headblock.vtype) )
  1264.     {
  1265.         ioset(TYIOINT, XUNIT, cpexpr(p) );
  1266.         putiocall( call1(TYINT, subname, cpexpr((expptr)ioblkp) ));
  1267.     }
  1268.     else
  1269.         err("bad unit in I/O motion statement");
  1270. }
  1271.  
  1272. static int ioset_assign = OPASSIGN;
  1273.  
  1274.  LOCAL void
  1275. #ifdef KR_headers
  1276. ioset(type, offset, p)
  1277.     int type;
  1278.     int offset;
  1279.     register expptr p;
  1280. #else
  1281. ioset(int type, int offset, register expptr p)
  1282. #endif
  1283. {
  1284.     offset /= SZLONG;
  1285.     if(statstruct && ISCONST(p)) {
  1286.         register char *s;
  1287.         switch(type) {
  1288.             case TYADDR:    /* stmt label */
  1289.                 s = "fmt_";
  1290.                 break;
  1291.             case TYIOINT:
  1292.                 s = "";
  1293.                 break;
  1294.             default:
  1295.                 badtype("ioset", type);
  1296.             }
  1297.         iob_list->fields[offset] =
  1298.             string_num(s, p->constblock.Const.ci);
  1299.         frexpr(p);
  1300.         }
  1301.     else {
  1302.         register Addrp q;
  1303.  
  1304.         q = ALLOC(Addrblock);
  1305.         q->tag = TADDR;
  1306.         q->vtype = type;
  1307.         q->vstg = STGAUTO;
  1308.         q->ntempelt = 1;
  1309.         q->isarray = 0;
  1310.         q->memoffset = ICON(0);
  1311.         q->uname_tag = UNAM_IDENT;
  1312.         sprintf(q->user.ident, "%s.%s",
  1313.             statstruct ? iob_list->name : ioblkp->user.ident,
  1314.             io_fields[offset + 1]);
  1315.         if (type == TYADDR && p->tag == TCONST
  1316.                    && p->constblock.vtype == TYADDR) {
  1317.             /* kludge */
  1318.             register Addrp p1;
  1319.             p1 = ALLOC(Addrblock);
  1320.             p1->tag = TADDR;
  1321.             p1->vtype = type;
  1322.             p1->vstg = STGAUTO;    /* wrong, but who cares? */
  1323.             p1->ntempelt = 1;
  1324.             p1->isarray = 0;
  1325.             p1->memoffset = ICON(0);
  1326.             p1->uname_tag = UNAM_IDENT;
  1327.             sprintf(p1->user.ident, "fmt_%ld",
  1328.                 p->constblock.Const.ci);
  1329.             frexpr(p);
  1330.             p = (expptr)p1;
  1331.             }
  1332.         if (type == TYADDR && p->headblock.vtype == TYCHAR)
  1333.             q->vtype = TYCHAR;
  1334.         putexpr(mkexpr(ioset_assign, (expptr)q, p));
  1335.         }
  1336. }
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  LOCAL void
  1342. #ifdef KR_headers
  1343. iosetc(offset, p)
  1344.     int offset;
  1345.     register expptr p;
  1346. #else
  1347. iosetc(int offset, register expptr p)
  1348. #endif
  1349. {
  1350.     if(p == NULL)
  1351.         ioset(TYADDR, offset, ICON(0) );
  1352.     else if(p->headblock.vtype == TYCHAR) {
  1353.         p = putx(fixtype((expptr)putchop(cpexpr(p))));
  1354.         ioset(TYADDR, offset, addrof(p));
  1355.         }
  1356.     else
  1357.         err("non-character control clause");
  1358. }
  1359.  
  1360.  
  1361.  
  1362.  LOCAL void
  1363. #ifdef KR_headers
  1364. ioseta(offset, p)
  1365.     int offset;
  1366.     register Addrp p;
  1367. #else
  1368. ioseta(int offset, register Addrp p)
  1369. #endif
  1370. {
  1371.     char *s, *s1;
  1372.     static char who[] = "ioseta";
  1373.     expptr e, mo;
  1374.     Namep np;
  1375.     ftnint ci;
  1376.     int k;
  1377.     char buf[24], buf1[24];
  1378.     Extsym *comm;
  1379.     extern int usedefsforcommon;
  1380.  
  1381.     if(statstruct)
  1382.     {
  1383.         if (!p)
  1384.             return;
  1385.         if (p->tag != TADDR)
  1386.             badtag(who, p->tag);
  1387.         offset /= SZLONG;
  1388.         switch(p->uname_tag) {
  1389.             case UNAM_NAME:
  1390.             mo = p->memoffset;
  1391.             if (mo->tag != TCONST)
  1392.                 badtag("ioseta/memoffset", mo->tag);
  1393.             np = p->user.name;
  1394.             np->visused = 1;
  1395.             ci = mo->constblock.Const.ci - np->voffset;
  1396.             if (np->vstg == STGCOMMON
  1397.             && !np->vcommequiv
  1398.             && !usedefsforcommon) {
  1399.                 comm = &extsymtab[np->vardesc.varno];
  1400.                 sprintf(buf, "%d.", comm->curno);
  1401.                 k = strlen(buf) + strlen(comm->cextname)
  1402.                     + strlen(np->cvarname);
  1403.                 if (ci) {
  1404.                     sprintf(buf1, "+%ld", ci);
  1405.                     k += strlen(buf1);
  1406.                     }
  1407.                 else
  1408.                     buf1[0] = 0;
  1409.                 s = mem(k + 1, 0);
  1410.                 sprintf(s, "%s%s%s%s", comm->cextname, buf,
  1411.                     np->cvarname, buf1);
  1412.                 }
  1413.             else if (ci) {
  1414.                 sprintf(buf,"%ld", ci);
  1415.                 s1 = p->user.name->cvarname;
  1416.                 k = strlen(buf) + strlen(s1);
  1417.                 sprintf(s = mem(k+2,0), "%s+%s", s1, buf);
  1418.                 }
  1419.             else
  1420.                 s = cpstring(np->cvarname);
  1421.             break;
  1422.             case UNAM_CONST:
  1423.             s = tostring(p->user.Const.ccp1.ccp0,
  1424.                 (int)p->vleng->constblock.Const.ci);
  1425.             break;
  1426.             default:
  1427.             badthing("uname_tag", who, p->uname_tag);
  1428.             }
  1429.         /* kludge for Hollerith */
  1430.         if (p->vtype != TYCHAR) {
  1431.             s1 = mem(strlen(s)+10,0);
  1432.             sprintf(s1, "(char *)%s%s", p->isarray ? "" : "&", s);
  1433.             s = s1;
  1434.             }
  1435.         iob_list->fields[offset] = s;
  1436.     }
  1437.     else {
  1438.         if (!p)
  1439.             e = ICON(0);
  1440.         else if (p->vtype != TYCHAR) {
  1441.             NOEXT("non-character variable as format or internal unit");
  1442.             e = mkexpr(OPCHARCAST, (expptr)p, ENULL);
  1443.             }
  1444.         else
  1445.             e = addrof((expptr)p);
  1446.         ioset(TYADDR, offset, e);
  1447.         }
  1448. }
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  LOCAL void
  1454. #ifdef KR_headers
  1455. iosetip(i, offset)
  1456.     int i;
  1457.     int offset;
  1458. #else
  1459. iosetip(int i, int offset)
  1460. #endif
  1461. {
  1462.     register expptr p;
  1463.  
  1464.     if(p = V(i))
  1465.         if(p->tag==TADDR &&
  1466.             ONEOF(p->addrblock.vtype, inqmask) ) {
  1467.             ioset_assign = OPASSIGNI;
  1468.             ioset(TYADDR, offset, addrof(cpexpr(p)) );
  1469.             ioset_assign = OPASSIGN;
  1470.             }
  1471.         else
  1472.             errstr("impossible inquire parameter %s", ioc[i].iocname);
  1473.     else
  1474.         ioset(TYADDR, offset, ICON(0) );
  1475. }
  1476.  
  1477.  
  1478.  
  1479.  LOCAL void
  1480. #ifdef KR_headers
  1481. iosetlc(i, offp, offl)
  1482.     int i;
  1483.     int offp;
  1484.     int offl;
  1485. #else
  1486. iosetlc(int i, int offp, int offl)
  1487. #endif
  1488. {
  1489.     register expptr p;
  1490.     if( (p = V(i)) && p->headblock.vtype==TYCHAR)
  1491.         ioset(TYIOINT, offl, cpexpr(p->headblock.vleng) );
  1492.     iosetc(offp, p);
  1493. }
  1494.